package com.ruoyi.flow.core.response;

/**
 * 封装返回给前端的metadata
 *
 * @author wtian
 */
public class Meta {

    public static enum META_CODE{
        SUCCESS(200,"请求成功"),
        ERROR(400,"请求失败");
        private int code;
        private String message;

        META_CODE(int code, String message) {
            this.code = code;
            this.message = message;
        }

        public int getCode() {
            return code;
        }

        public String getMessage() {
            return message;
        }
    }

    private Integer code;

    private String message;

    public Meta() {
    }

    public Meta(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public Meta setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Meta setMessage(String message) {
        this.message = message;
        return this;
    }

    public <T> Response<T> create() {
        return new Response<T>(this);
    }

    /**
     * 生成成功的响应信息
     *
     * @return
     */
    public Meta success() {
        int code = META_CODE.SUCCESS.getCode();
        String message = META_CODE.SUCCESS.getMessage();
        return new Meta(code,message);
    }

    /**
     * 生成失败的响应信息
     *
     * @return
     */
    public Meta error() {
        int code = META_CODE.ERROR.getCode();
        String message = META_CODE.ERROR.getMessage();
        return new Meta(code,message);
    }
}
